package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Rest风格开发
 *
 * @author lixu
 */
@Controller
@RequestMapping("/user")
public class RestController {


//    1、删除用户ID为3的数据 请求方式：POST  GET  DELETE PUT
//    http://localhost:8080/user/3/xiaozhang   请求方式：DELETE

    // @PathVariable : 从路径上获取到变量值
    @RequestMapping(value = "/{id}/{name}",method = {RequestMethod.DELETE}) // ==@DeleteMapping
    public String test1(@PathVariable(value = "id") Integer id, @PathVariable String name) {
        System.out.println("id:" + id);
        return "hello";
    }

    //            2、查询用户ID为3的数据
//    http://localhost:8080/user/3   请求方式：GET
    @RequestMapping(value = "/{id}",method = {RequestMethod.GET}) // == @GetMapping
    public String test2(@PathVariable(value = "id") Integer id) {
        System.out.println("id:" + id);
        return "hello";
    }

    //            3、添加用户
//    http://localhost:8080/user     请求方式：POST
//    传递参数 请求体  <form>
    @RequestMapping(method = {RequestMethod.POST})
    public String test3(User user) {
        return "hello";
    }


    //4、修改用户ID为3   用户名：张三 改 李四
//    http://localhost:8080/user/3   请求方式：PUT
//    传递参数 请求体  <form>
    @RequestMapping(value = "/{id}",method = {RequestMethod.PUT})
    public String test4(@PathVariable(value = "id") Integer id,User user) {
        System.out.println("id:" + id);
        return "hello";
    }
}
